(defun pentagonal(n)
  (/ (* n (1- (* 3 n))) 2))

(defun pentagonal-root(n)
  (/ (1+ (sqrt (coerce (1+ (* 24 n)) 'double-float))) 6))

(defun pentagonalp(n)
;  (typep (pentagonal-root n) 'integer))
  (let ((p (pentagonal-root n)))
    (zerop (- p (floor p)))))

(defun hexagonal(n)
  (* n (1- (* 2 n))))

(defun probl45()
  (loop for i = 144 then (1+ i)
     for hexa = (hexagonal i) 
     until (pentagonalp hexa)
     when (= i 27693)
     do (print hexa)
     ;when (zerop (mod i 1000))
     ;do (print i)
     finally (return hexa)))
	 
(defun trianglep(n)
  (/ (* n (1+ n)) 2))

(defun pentagonalp(n)
  (/ (* n (1- (* 3 n))) 2))

(defun hexagonalp (n)
  (* n (1- (* 2 n))))

(defun naive(max)
  (intersection 
   (intersection (loop for i from 1 to max collect (trianglep i)) 
		 (loop for i from 1 to max collect (pentagonalp i)))
		 (loop for i from 1 to max collect (hexagonalp i))))